from django.db import models, signals
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
import os
import re

# Create your models here.
def get_folder_list(user=''):
    path = "/home/www/%s" % user
    DIR_CHOICES = []
    hide_re = re.compile('/\.')
    show_re = re.compile('^/[^/]*/[^/]*(:?|/[^/]*(:?|/[^/]*))$')
    for root, dirs, files in os.walk(path):
        if not re.search(hide_re, root) and re.match(show_re, root):
            root += '/'
            DIR_CHOICES.append((root, root.replace(path, "", 1)))
    return DIR_CHOICES

class FTPUser(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField('Username', max_length=25, unique=True)
    password = models.CharField(max_length=25)
    directory = models.CharField(max_length=255, default=None, null=True)

    def __unicode__(self):
        return "%s - %s - %s" % (self.user,self.name,self.directory)
